#include"TcpServer.hpp"
#include<memory>
#include"Http.hpp"
using namespace hcc;

HttpResponse Login(HttpRequest&req)
{
    HttpResponse resp;
    std::cout<<"外部已经拿到了参数: "<<std::endl;
    req.GetResuestBody();
    std::cout<<"##########################" <<std::endl;
    resp.AddCode(200,"ok");
    resp.AddBodyText("<html><h1>result done!</h1></html>");

    return resp;
}
//  ./xxx port
int main(int argc,char *argv[])
{
    if(argc!=2)
    {
        std::cout<<"Usage "<<argv[0]<<std::endl;
        exit(0);
    }
    EnableScreen();
    uint16_t port=std::stoi(argv[1]);
    
    HttpServer ht;
    ht.InsertService("/login",Login);
    std::unique_ptr<TcpServer>tsvr=std::make_unique<TcpServer>(std::bind(&HttpServer::HandlerHttpRequest,&ht,
    std::placeholders::_1),
    port);
    tsvr->Loop();
    
    return 0;
}